package com.yun.controller;


import com.yun.pojo.Evaluate;
import com.yun.pojo.User;
import com.yun.service.EvaluateService;
import com.yun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.swing.plaf.nimbus.State;
import java.util.List;

@Controller
public class EvaluateController {

    @Autowired
    EvaluateService evaluateService;
    @Autowired
    UserService userService;

    @RequestMapping("/getEvaluate")
    public String getEvaluate(Model model){
        List<Evaluate> evaluates = evaluateService.getEvaluate();
        model.addAttribute("evaluates",evaluates);
        return "user/userInfo";
    }
    @RequestMapping("/EvaluatePage")
    public String EvaluatePage(Model model){
        List<User> username = userService.getUser();
        model.addAttribute("users",username);

        return "user/evaluate";
    }
    @RequestMapping("/evaluate")
    public String evaluate(Evaluate evaluate,Model model){
        evaluateService.addEvaluate(evaluate);
        List<Evaluate> evaluates = evaluateService.getEvaluate();
        model.addAttribute("evaluates",evaluates);
        return "user/userInfo";
    }
    @RequestMapping("/collection")
    public String collection(Model model) {
        List<Evaluate> evaluates = evaluateService.queryState(1);
        model.addAttribute("List",evaluates);
        return "director/collection";
    }

    @RequestMapping("/deleteEvaluate/{id}")
    public String  deleteEvaluate(@PathVariable("id")int id,Model model){
        evaluateService.deleteEvaluate(id);
        List<Evaluate> evaluate = evaluateService.queryState(0);
        model.addAttribute("evaluate",evaluate);
        return "director/consult";
    }
    @RequestMapping("/deleteCollection/{id}")
    public String  deleteCollection(@PathVariable("id")int id,Model model){
        evaluateService.deleteEvaluate(id);
        List<Evaluate> evaluate = evaluateService.queryState(1);
        model.addAttribute("List",evaluate);
        return "director/collection";
    }

    @RequestMapping("/updateState/{id}")
    public String updateState(@PathVariable("id")int id,Model model){
        evaluateService.updateState(id,1);
        List<Evaluate> evaluate = evaluateService.queryState(0);
        model.addAttribute("evaluate",evaluate);
        return "director/consult";
    }

    @RequestMapping("/updateStates/{id}")
    public String updateStates(@PathVariable("id")int id,Model model){
        evaluateService.updateState(id,0);
        List<Evaluate> evaluate = evaluateService.queryState(1);
        model.addAttribute("List",evaluate);
        return "director/collection";
    }

}